#coding=utf-8
import mongo
import cache
import status
import datetime
import hashlib

def handler(client,ip_str,data):
    ret = [{"rep":data["req"],"status":status.SUCCESS},[],{},False]
    data = mongo.get_user(data["name"],hashlib.md5(data["passwd"]).hexdigest())
    if not data:
        ret[0]["status"] = status.FAILED
        return ret
    # 生成TOKEN
    token = hashlib.md5(datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")).hexdigest()
    cache.set_session(data["id"],client,data["name"],token)
    ret[0]["token"] = token
    ret[0]["uid"] = data["id"]
    return ret
